package com.lovo.pz.window;

import com.lovo.pz.util.GameUtil;
import com.lovo.pz.util.UserBean;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
/**
 * 排行榜界面
 * @author 白德柯
 *
 */
public class RankPanel extends JPanel implements MouseListener {
    private MainFrame mainFrame;
    public RankPanel(MainFrame mainFrame){
        this.mainFrame = mainFrame;
        this.addMouseListener(this);

    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(GameUtil.rankBackgroundImage,0,0,900,600,this);

        // 渲染“返回菜单”文字
        g.setFont(new Font("黑体",Font.BOLD,40));
        g.setColor(Color.GREEN);
        g.drawString("返回菜单",50,200);

        // 渲染排行榜的头部文字
        g.setFont(new Font("黑体",Font.BOLD,30));
        g.setColor(Color.BLACK);
        g.drawString("名称",500,150);
        g.drawString("分数",700,150);

        // 渲染玩家信息
        g.setFont(new Font("黑体",Font.BOLD,25));
        g.setColor(Color.RED);
        List<UserBean> users = mainFrame.getUsers();
        for(int i = 0;i < 5;i++){
            if(i < users.size()){
                g.drawString(users.get(i).getName(),500,200 + i * 40);
                g.drawString(users.get(i).getScore() + "",700,200 + i * 40);

            }
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();

        if(x > 50 && x < 210 && y > 160 && y < 200){
            mainFrame.switchPanel("menu");
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}

    @Override
    public void mouseEntered(MouseEvent e) {}

    @Override
    public void mouseExited(MouseEvent e) {}
}
